import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class Portfolio extends Thread{
	
	private Connection conn;
	private Statement stmt = null;
	private ResultSet rs = null;

	public Portfolio(String str, Connection conn){
		super(str);
		this.conn = conn;
	}
	
	public void run(){
		String sqlQuery = "SELECT * FROM Portfolio";
		try {
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sqlQuery);
			while(rs.next()){
				synchronized(System.class) {
				System.out.print(rs.getString(2) + " Quantity:" + rs.getString("quantity"));
				sleep(100);
				double totalValue = rs.getInt("quantity") * rs.getDouble("price");
				System.out.println(" Total value = " + totalValue);
				}}
		} catch (SQLException e) {
			System.out.println("SQL Error: " + e.getMessage() +
					" code: " + e.getErrorCode());
		}
		
		catch (InterruptedException ie){
			ie.printStackTrace();
		}
		finally{
			try {
				rs.close();
				stmt.close();
				conn.close();
			} catch (SQLException e) {
				System.out.println("SQL Error: " + e.getMessage() +
						" code: " + e.getErrorCode());
			}
			
		}
	}
	
}

